package com.mengshuai.mysql.controller.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mongo")
public class MongoController {
    @Autowired
    private BookService bookService;

    @GetMapping("/findByAuthor1")
    public List<Book> findByAuthor1(@RequestParam String author) {
        return bookService.findByAuthor1(author);
    }

    @GetMapping("/findByAuthor")
    public List<Book> findByAuthor(String author) {
        return bookService.findByAuthor(author);
    }

    @PostMapping("/insertOne")
    public void insertOne(@RequestBody Book book) {
        bookService.insertOne(book);
    }

    @GetMapping("/deleteOne")
    public void deleteOne(@RequestParam String id) {
        bookService.deleteOne(id);
    }

    @PostMapping("/updateOne")
    public void updateOne(@RequestBody Book book) {
        bookService.updateOne(book);
    }
}
